// api/role.ts
import type { RoleForm } from '@/types/role';
import {http} from '@/utils/http'

// 获取角色列表
export const getRoleList = (params: any): Promise<any> => {
  return http.get('/api/role/index', { params });
};

// 获取角色详情
export const getRoleDetail = (id: number): Promise<any> => {
  return http.get(`/api/role/read?id=${id}`);
};

// 获取角色详情 （分管理员）
export const getRoleDetailFind = (id: number,system_user_id:number|string): Promise<any> => {
  return http.get(`/api/role/read_find?id=${id}&system_user_id=${system_user_id}`);
};


// 添加角色
export const addRole = (data: RoleForm): Promise<any> => {
  return http.post('/api/role/save', data);
};

// 更新角色
export const updateRole = (data: RoleForm): Promise<any> => {
    return http.post('/api/role/update', data);
};

//更新角色的权限
export const updateRole2 = (data: RoleForm): Promise<any> => {
    return http.post('/api/role/update2', data);
};

//更新角色的权限（分账号）
export const updateRole3 = (id:string|number,data: any): Promise<any> => {
    let json = {
      id:2,
      system_user_id:id,
      menuIds:data
    }
    return http.post('/api/role/update3', json);
};

// 删除角色
export const deleteRole = (id: number): Promise<any> => {
  return http.post('/api/role/delete', {id:id});
};

// 获取菜单树
export const getMenuTree = (): Promise<any> => {
  return http.get('/api/menu/role_tree');
};

export const getMenuTrees = (): Promise<any> => {
  return http.get('/api/menu/treeByBusiness');
};

export const getPermissions = (id: number): Promise<any> => {
  return http.get('/api/Permission/getUserPermissions', {userId:id});
};

export const reload_permission = (id: number): Promise<any> => {
  return http.get('/api/Permission/reload_permission', {userId:id});
};

export const tenant_list = (): Promise<any> => {
  return http.get('/api/role/tenant_list');
};